package tk.hoopy.zedtown;

import tk.hoopy.zedtown.assets.AssetManager;
import tk.hoopy.zedtown.graphics.GameWindow;
import tk.hoopy.zedtown.input.InputManager;
import tk.hoopy.zedtown.levels.Generator;
import tk.hoopy.zedtown.levels.Level;
import tk.hoopy.zedtown.levels.LevelManager;

public class Launcher {
	
	private static final long FPS = 120;

	public static void main(String[] args) {
		
		AssetManager.LoadAssets();
		
		GameWindow gameWindow = new GameWindow("Zed Town", 8, 4);
		InputManager inputManager = new InputManager(gameWindow);
		
		GameSession.SetupConstantObjects(inputManager,gameWindow);
		
		LevelManager levelMan = new LevelManager();
		Level testLevel = new Level(15, new Generator(),0);
		
		GameSession gameSession = new GameSession(levelMan);
		
		levelMan.AttachWindow(gameWindow);
		levelMan.SetLevel(testLevel);
		
		long delta = 0, oldTime = System.currentTimeMillis();
		while(true) {
			oldTime = System.currentTimeMillis();
			delta = System.currentTimeMillis() - oldTime;
			while(delta < 1000f/FPS) {
				delta = System.currentTimeMillis() - oldTime;
			}
			
			gameSession.PerformEntityLogic();
			gameSession.PerformLevelLogic();
			gameSession.Draw();
			gameWindow.Refresh();
		}
	}
	
}
